package listener;

import dao.EquipmentDaoImpl;
import utils.string.session.SessionStringUtil;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.util.HashMap;

public class AllEquipmentListener implements HttpSessionListener {
    //该监听器是为了读取所有可用的设备
    @Override
    public void sessionCreated(HttpSessionEvent se) {
        EquipmentDaoImpl equipmentDao = new EquipmentDaoImpl();
        HashMap equipments =  equipmentDao.selectAll();
        HttpSession session = se.getSession();
        session.setAttribute(SessionStringUtil.ALL_UNUSED_EQUIPMENTS,equipments);
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        EquipmentDaoImpl equipmentDao = new EquipmentDaoImpl();
        HashMap equipments =  equipmentDao.selectAll();
        HttpSession session = se.getSession();
        session.setAttribute(SessionStringUtil.ALL_UNUSED_EQUIPMENTS,equipments);
        }
}
